<%@ page language="java" pageEncoding="UTF-8"%><%@ taglib prefix="aurorapt" uri="http://java.aurora.com/aurora/permission"%>
<!DOCTYPE html>
<html>
<head>
<title>仓库管理</title>
<meta name="content-type" content="text/html; charset=UTF-8">
<jsp:include page="/pub.jsp"></jsp:include>
<script type="text/javascript">
var aotemaiWarehouseDataGrid;
$(function() {
	aotemaiWarehouseDataGrid = $('#aotemaiWarehouse_datagrid').datagrid({
		url : '${pageContext.request.contextPath}/aotemaiWarehouse/list',
		fit : true,
		fitColumns : true,
		border : false,
		pagination : true,
		idField : 'id',
		pagePosition : 'both',
		checkOnSelect:true,
		selectOnCheck:true,
		columns : [ [ {
			field : 'id',
			title : '编号',
			width : 100,
			checkbox : true
		}, {
			field : 'ID',
			title : '仓库ID',
			width : 60,
        	formatter: function(value,row,index){
        		return '<span style="color:blue;width:100px;">'+ row.id +'</span>';
			}
		}, {
			field : 'contact',
			title : '联系人',
			width : 100
		}, {
			field : 'name',
			title : '仓库名',
			width : 100
		}, {
			field : 'address',
			title : '详细地址',
			width : 100
		}, {
			field : 'mobile',
			title : '手机号',
			width : 100
		}, {
			field : 'longitude',
			title : '经度',
			width : 100
		}, {
			field : 'latitude',
			title : '纬度',
			width : 100
		}] ],
		onLoadSuccess:function(){
            $(this).datagrid('doCellTip',{'max-width':'300px','delay':500});
        },
		onRowContextMenu:function(e, rowIndex, rowData){
			e.preventDefault();
			$(this).datagrid('clearSelections');
			$(this).datagrid('clearChecked');
			$(this).datagrid('selectRow',rowIndex);
			$('#aotemaiWarehouse_menu').menu('show', {
				left : e.pageX,
				top : e.pageY
			});
		},toolbar:'#tb'
	});
	
});

function aotemaiWarehouseAdd() {
	var dialog = parent.modalDialog({
		title : '仓库添加',
		width : 500,
		height : 400,
		url : '${pageContext.request.contextPath}/aotemaiWarehouse/addUI',
		buttons : [ {
			text : '添加',
			handler : function() {
				dialog.find('iframe').get(0).contentWindow.aotemaiWarehouse_add_submitForm(dialog, aotemaiWarehouseDataGrid, parent.$);
			}
		} ]
	});
}

function aotemaiWarehouseEdit(){
	var rows = aotemaiWarehouseDataGrid.datagrid('getChecked');
	if(rows.length==1){
		var dialog = parent.modalDialog({
			title : '仓库编辑',
			width : 500,
			height : 400,
			url : '${pageContext.request.contextPath}/aotemaiWarehouse/editUI/'+rows[0].id,
			buttons : [ {
				text : '编辑',
				handler : function() {
					dialog.find('iframe').get(0).contentWindow.aotemaiWarehouse_edit_submitForm(dialog, aotemaiWarehouseDataGrid, parent.$);
				}
			} ]
		});
	}else{
		parent.$.messager.alert('提示','请选择一条记录进行操作');
	}
}
function aotemaiWarehouseDelete(){
	var rows = aotemaiWarehouseDataGrid.datagrid('getChecked');
	if(rows.length==1){
		$.messager.confirm('确认','您确认想要删除记录吗？',function(r){
		    if (r){
				$.post('${pageContext.request.contextPath}/aotemaiWarehouse/delete', {id:rows[0].id}, function(j) {
					if (j.success) {
						aotemaiWarehouseDataGrid.datagrid('reload');
					}
					aotemaiWarehouseDataGrid.datagrid('uncheckAll');
					$.messager.show({
						title : '提示',
						msg : j.msg,
						timeout : 5000,
						showType : 'slide'
					});
				}, 'json').error(function() {
					$.messager.show({
						title : '提示',
						msg : '你的权限不够',
						timeout : 5000,
						showType : 'slide'
					});
				});
		    }    
		});
	}else{
		parent.$.messager.alert('提示','请选择一条记录进行操作');
	}
}
/* ------------------------------拓展功能 --------------------- */

function aotemaiWarehouse_searchFun() {
	$('#aotemaiWarehouse_datagrid').datagrid('load', serializeObject($('#aotemaiWarehouse_searchForm')));
}
function aotemaiWarehouse_clearFun() {
	$('#aotemaiWarehouse_searchForm input').val('');
}
</script>
</head>

<body>
<div class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'center',border:false,title:'仓库列表'" style="overflow: hidden;">
		<table id="aotemaiWarehouse_datagrid"></table>
	</div>
</div>

<div id="tb" style="padding:2px 5px;">
	<form id="aotemaiWarehouse_searchForm">
		<aurorapt:permission privilege="warehouse_addUI">
		<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="ext-icon-add" onclick="aotemaiWarehouseAdd();">添加</a></aurorapt:permission>
		<aurorapt:permission privilege="warehouse_editUI">
		<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="ext-icon-pencil" onclick="aotemaiWarehouseEdit();">修改</a></aurorapt:permission>
		<aurorapt:permission privilege="warehouse_delete">
		<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-no" onclick="aotemaiWarehouseDelete();">删除</a></aurorapt:permission>
		
		仓库名：<input class="easyui-textbox" name="name"/>
        <a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-search" onclick="aotemaiWarehouse_searchFun();">查询</a>
        <a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-clear" onclick="aotemaiWarehouse_clearFun();">清空</a>
	</form>
</div>

<div id="aotemaiWarehouse_menu" class="easyui-menu" style="width: 120px;display: none;">
	<aurorapt:permission privilege="warehouse_addUI">
	<div onclick="aotemaiWarehouseAdd()" iconCls="icon-add">增加</div></aurorapt:permission>
	<aurorapt:permission privilege="warehouse_editUI">
	<div onclick="aotemaiWarehouseEdit()" iconCls="icon-edit">编辑</div></aurorapt:permission>
	<aurorapt:permission privilege="warehouse_delete">
	<div onclick="aotemaiWarehouseDelete()" iconCls="icon-no">删除</div></aurorapt:permission>
</div>
</body>
</html>